import Data.List
import Data.Maybe


type InitialValue = Integer
type NumberOfRounds = Integer
type MaxRounds = Integer
type FinalValue = Integer
type TextRep = String
data Solution = Failure | Success (NumberOfRounds, FinalValue, TextRep) deriving (Eq, Show)


isPalindrom i = (show i) == (reverse $ show i)

palindromNum i = read $ reverse $ show i

solve r m i
  | r > m = (False,r,i)
  | isPalindrom s = (True,r,s)
  | otherwise = solve (r+1) m s
  where
    p = palindromNum i
    s = i + p

addRev i m
  | isPalindrom i = Success (0,i,show i)
  | solved = Success (r,value,show value)
  | otherwise = Failure
  where
    (solved,r,value) = solve 1 (abs(m)) (abs(i))

{--
type Country = String
type Countries = [Country]
type TravelTime = Integer
data Connection = Air Country Country TravelTime
                | Sea Country Country TravelTime
                | Rail Country Country TravelTime
                | Road Country Country TravelTime deriving (Eq,Ord,Show)
type Connections = [Connection]
data Itinerary = NoRoute | Route (Connections,TravelTime) deriving (Eq,Ord,Show)


getFrom (Air from _ _) = from
getFrom (Sea from _ _) = from
getFrom (Rail from _ _) = from
getFrom (Road from _ _) = from

getTo (Air _ to _) = to
getTo (Sea _ to _) = to
getTo (Rail _ to _) = to
getTo (Road _ to _) = to

isRoute :: Connections -> Country -> Country -> Bool
isRoute conns from to
  | isJust mSolution = True
  | otherwise = or $ [isRoute conns' (getTo cand) to | cand <- candidates, let conns' = delete cand conns]
  where
    candidates = filter (\c -> getFrom c == from) conns

    mSolution = find (\c -> getTo c == to) candidates


conn1 = Air "A" "B" 5
conn2 = Sea "B" "C" 5

conns = [conn1,conn2]
--}
